unit uniStatusDisplay;

interface

uses
  uniHeroAircraft,
  uniDefine,
  ftgl,
  gl,
  SysUtils,
  Classes;

const
  str1 = 'do not let -any- ships past you! each one costs you a life!';
  str2 = 'let super shields pass by for an extra life!';

type
  { StatusDisplay }

  StatusDisplay = class(TObject)
  public
    statTex: GLuint;
    shldTex: GLuint;
    topTex: GLuint;
    heroSuperTex: GLuint;
    heroShieldTex: GLuint;
    heroAmmoFlash: array[0..NUM_HERO_AMMO_TYPES - 1] of GLuint;
    useFocus: GLuint;
    useItem: array[0..NUM_HERO_ITEMS - 1] of GLuint;

    ammoAlpha: Single;
    damageAlpha: Single;
    shieldAlpha: Single;
    blink: Boolean;

    tipShipShow: Integer;
    tipSuperShow: Integer;

    enemyWarn: Single;

    //game: Global;

    constructor Create;
    destructor Destroy; override;

    procedure darkenGL;
    procedure drawGL(hero: HeroAircraft);

    procedure setAmmoAlpha(_in: Single); {ammoAlpha = in;}
    procedure setDamageAlpha(_in: Single); {damageAlpha = in; }
    procedure setShieldAlpha(_in: Single); {shieldAlpha = in;}

    procedure enemyWarning(v: Single); {if(v > enemyWarn) enemyWarn = v; }

    procedure loadTextures;
    procedure deleteTextures;

    procedure drawQuad(szx, szy: Single);
    {
  glBegin(GL_TRIANGLE_STRIP);
   glTexCoord2f(1.0, 0.0); glVertex3f( szx,  szy, 0.0);
   glTexCoord2f(0.0, 0.0); glVertex3f(-szx,  szy, 0.0);
   glTexCoord2f(1.0, 1.0); glVertex3f( szx, -szy, 0.0);
   glTexCoord2f(0.0, 1.0); glVertex3f(-szx, -szy, 0.0);
  glEnd();
    }

  end;

var
  statPosAmmo: array[0..3 - 1] of Single = (-10.5, 8.00, 25.0);
  statPosShld: array[0..3 - 1] of Single = (-10.4, -7.80, 25.0);
  statClrWarn: array[0..4 - 1] of Single = (1.1, 0.6, 0.1, 1.1);
  statClrZero: array[0..4 - 1] of Single = (0.0, 0.0, 0.0, 0.0);
  statClrAmmo: array[0..NUM_HERO_AMMO_TYPES - 1, 0..4 - 1] of Single =
  (
    (1.0, 0.7, 0.5, 0.6),
    (0.0, 1.0, 0.5, 0.7),
    (0.3, 0.0, 1.0, 0.7)
    );

  rot: Single = 0;

implementation

uses
  PNGLoader,
  uniConfig,
  uniGlobal;

{ StatusDisplay }

constructor StatusDisplay.Create;
begin
  //game = Global::getInstance();

  ammoAlpha := 0.0;
  damageAlpha := 0.0;
  shieldAlpha := 0.0;

  enemyWarn := 0.0;

  tipShipShow := 0;
  tipSuperShow := 0;

  loadTextures;

  blink := true;
end;

procedure StatusDisplay.darkenGL;
begin
  //-- sidebars
  glBindTexture(GL_TEXTURE_2D, shldTex);

  glBegin(GL_QUADS);

  glColor4f(0.25, 0.2, 0.2, 0.6);
  glTexCoord2f(0.0, 0.0); glVertex3f(-9.2, 8.5, 25.0);
  glTexCoord2f(1.0, 0.0); glVertex3f(-11.5, 8.5, 25.0);
  glColor4f(0.25, 0.25, 0.35, 0.6);
  glTexCoord2f(1.0, 1.7); glVertex3f(-11.5, -8.5, 25.0);
  glTexCoord2f(0.0, 1.7); glVertex3f(-9.2, -8.5, 25.0);

  glColor4f(0.25, 0.2, 0.2, 0.6);
  glTexCoord2f(1.0, 0.0); glVertex3f(11.5, 8.5, 25.0);
  glTexCoord2f(0.0, 0.0); glVertex3f(9.2, 8.5, 25.0);
  glColor4f(0.25, 0.25, 0.35, 0.6);
  glTexCoord2f(0.0, 1.7); glVertex3f(9.2, -8.5, 25.0);
  glTexCoord2f(1.0, 1.7); glVertex3f(11.5, -8.5, 25.0);

  glEnd;
end;

procedure StatusDisplay.deleteTextures;
var
  i: Integer;
begin
  glDeleteTextures(1, @statTex);
  glDeleteTextures(1, @shldTex);
  glDeleteTextures(1, @heroSuperTex);
  glDeleteTextures(1, @heroShieldTex);
  for i := 0 to NUM_HERO_AMMO_TYPES - 1 do
  begin
    glDeleteTextures(1, @heroAmmoFlash[i]);
  end;
  for i := 0 to NUM_HERO_ITEMS - 1 do
  begin
    glDeleteTextures(1, @useItem[i]);
  end;
end;

destructor StatusDisplay.Destroy;
begin
  deleteTextures;
  //inherited;
end;

procedure StatusDisplay.drawGL(hero: HeroAircraft);
var
  _config: Config;
  game: Global;
  scoreBuf: string;
  i: Integer;
  statClrWarnAmmo: Boolean;
  w, x, y, y3: Single;
  size: array[0..1] of Single;
  ammoStock: Single;
  shields, superShields, damage: Single;
  a: Single;

  dc, sc, sl, szx, szy, sls, dl, dls, rot2: Single;
  c1f, c2f, esz: single;
  c1: array[0..3] of Single;
  c2: array[0..3] of Single;

  sz: Single;
  p, v: array[0..2] of Single;
  c: array[0..3] of Single;

  off: array[0..1] of Single;
begin
  _config := uniConfig.instance;
  game := uniGlobal.getInstance;

  statClrWarnAmmo := false;
  w := 0.1;
  x := 0.0;

  if not Boolean(hero) then Exit;

  if not Boolean(uniGlobal.frame mod 15) then blink := not blink;

  ammoAlpha := ammoAlpha * 0.96;

  shields := hero.getShields;
  superShields := 0.0;
  damage := hero.getDamage;

  if shields > HERO_SHIELDS then
  begin
    superShields := HERO_SHIELDS - (shields - HERO_SHIELDS);
    shields := HERO_SHIELDS;
  end;

  //-- draw score
  glColor4f(1.0, 1.0, 1.0, 0.4);
  glPushMatrix;
  //sprintf(scoreBuf, "%07d", (int)hero.getScore);
  scoreBuf := FormatCurr('0######', Round(hero.getScore));
  glTranslatef(-9.0, -8.2, 25.0);
  glScalef(0.025, 0.02, 1.0);
  //game.ftFont.Render(scoreBuf);
  ftglRenderFont(uniGlobal.ftFont, PAnsiChar(scoreBuf));
  glPopMatrix;

  //-- draw fps
  if Boolean(_config.showFPS) then
  begin
    glPushMatrix;
    //sprintf(scoreBuf, "%3.1f", game.fps);
    scoreBuf := FormatFloat('0##.#', uniGlobal.fps);
    glTranslatef(7.75, 8.0, 25.0);
    glScalef(0.018, 0.015, 1.0);
    //game.ftFont.Render(scoreBuf);
    ftglRenderFont(uniGlobal.ftFont, PAnsiChar(scoreBuf));
    glPopMatrix;
  end;

  //-- draw ship lives
  glPushMatrix;
  glColor4f(0.6, 0.6, 0.7, 1.0);
  glBindTexture(GL_TEXTURE_2D, _hero.heroTex);
  glTranslatef(10.2, 7.4, 25.0);
  size[0] := _hero.getSize(0) * 0.5;
  size[1] := _hero.getSize(1) * 0.5;
  for i := 0 to _hero.getLives - 1 do
  begin
    drawQuad(size[0], size[1]);
    glTranslatef(0.0, -size[1] * 2.0, 0.0);
  end;
  glPopMatrix;

  //-- draw usable items
  if _config.gfxLevel() > 1 then
  begin
    glPushMatrix;
    glColor4f(1.0, 1.0, 1.0, 1.0);
    glTranslatef(8.5, -7.7, 25.0);
    size[0] := 0.4;
    size[1] := 0.5;
    for i := 0 to NUM_HERO_ITEMS - 1 do
    begin
      if i = _hero.currentItem then
      begin
        a := _hero.itemArmed * 0.8;
        glColor4f(0.4 + a, 0.4, 0.4, 0.4 + a);
        glBindTexture(GL_TEXTURE_2D, useFocus);
        drawQuad(size[1], size[1]);
        glColor4f(1.0, 1.0, 1.0, 1.0);
      end;
      glBindTexture(GL_TEXTURE_2D, useItem[i]);
      drawQuad(size[0], size[0]);
      glTranslatef(-size[1] * 2.0, 0.0, 0.0);
    end;
    glPopMatrix;
  end;

  //-- draw 'enemy-got-past' Warning
  //if Boolean(Round(enemyWarn)) and (_hero.getLives >= 0) then
  if (enemyWarn <> 0) and (_hero.getLives >= 0) then
  begin
    glPushMatrix;
    glColor4f(1.0, 0.0, 0.0, enemyWarn + 0.15 * sin(uniGlobal.gameFrame * 0.7));
    glTranslatef(0.0, -8.75, 25.0);
    glBindTexture(GL_TEXTURE_2D, heroAmmoFlash[0]);
    drawQuad(12.0, 3.0);
    glPopMatrix;
    enemyWarn := 0.0;
  end;

  //-- draw AMMO
  glPushMatrix;
  glTranslatef(statPosAmmo[0], statPosAmmo[1], statPosAmmo[2]);

  //--draw ammo reserves
  glBindTexture(GL_TEXTURE_2D, statTex);
  glBegin(GL_QUADS);
  for i := 0 to NUM_HERO_AMMO_TYPES - 1 do
  begin
    glColor4fv(@statClrAmmo[i]);
    ammoStock := hero.getAmmoStock(i);
    if ammoStock > 0.0 then
    begin
      x := i * 0.3;
      y := ammoStock * 0.02;
      y3 := y * 2.65;
      if blink or (ammoStock > 50.0) then glColor4fv(@statClrAmmo[i])
      else
      begin
        statClrWarnAmmo := true;
        glColor4fv(@statClrWarn);
      end;
      glTexCoord2f(1.0, 0.00); glVertex3f(x + w, -y3, 0.0);
      glTexCoord2f(1.0, y); glVertex3f(x + w, 0.0, 0.0);
      glTexCoord2f(0.0, y); glVertex3f(x - w, 0.0, 0.0);
      glTexCoord2f(0.0, 0.00); glVertex3f(x - w, -y3, 0.0);
    end;
  end;
  glEnd;

  glBindTexture(GL_TEXTURE_2D, topTex);
  if Boolean(statClrWarnAmmo) then
    glColor4f(statClrWarn[0], statClrWarn[1], statClrWarn[2], 0.5 + ammoAlpha)
  else
    glColor4f(0.5, 0.5, 0.5 + ammoAlpha, 0.2 + ammoAlpha);
  glBegin(GL_QUADS);
  glTexCoord2f(1.0, 1.0); glVertex3f(1.25, -1.85, 0.0);
  glTexCoord2f(1.0, 0.0); glVertex3f(1.25, 0.47, 0.0);
  glTexCoord2f(0.0, 0.0); glVertex3f(-0.75, 0.47, 0.0);
  glTexCoord2f(0.0, 1.0); glVertex3f(-0.75, -2.85, 0.0);
  glEnd;
  x := x + w * 1.5;
  glPopMatrix;


  //--draw Shields
  damageAlpha := damageAlpha * 0.94;
  shieldAlpha := shieldAlpha * 0.94;
  dc := damageAlpha * 0.5;
  sc := shieldAlpha * 0.5;
  szx := 0.5;
  szy := 6.0;
  rot := rot + 2.0 * uniGlobal.speedAdj;
  rot2 := 2 * (Round(rot) mod 180);
  sl := (shields / HERO_SHIELDS) - 1.0;
  sls := (shields / HERO_SHIELDS) - 1.0;
  dl := (damage / HERO_DAMAGE) - 1.0;
  dls := (damage / HERO_DAMAGE) - 1.0;
  //if Boolean(Round(superShields)) then
  if (superShields <> 0) then
  begin
    sls := ((shields + superShields) / HERO_SHIELDS) - 1.0;
    dls := ((shields + superShields) / HERO_SHIELDS) - 1.0;
  end;

  //------ draw Engine
  if hero.isVisible and (_config.gfxLevel() >= 1) then
  begin
    c1f := 1.0 + dl;
    c2f := -dl;
    //float c1[4] := { 0.85, 0.65, 1.00, 0.7 };
    //float c2[4] := { 1.00, 0.20, 0.25, 0.7 };
    c1[0] := 0.85;
    c1[1] := 0.65;
    c1[2] := 1.00;
    c1[3] := 0.7;

    c2[0] := 1.00;
    c2[1] := 0.20;
    c2[2] := 0.25;
    c2[3] := 0.7;

    glColor4f(c1[0] * c1f + c2[0] * c2f,
      c1[1] * c1f + c2[1] * c2f,
      c1[2] * c1f + c2[2] * c2f,
      c1[3] * c1f + c2[3] * c2f);
    glBindTexture(GL_TEXTURE_2D, heroAmmoFlash[0]);
    glPushMatrix;
    glTranslatef(hero.pos[0], hero.pos[1] - 0.625, hero.pos[2]);
    esz := 1.0 + c2f;
    drawQuad(1.3, 0.5 * esz);
    glTranslatef(0.0, -0.18, 0.0);
    glRotatef(IRAND, 0.0, 0.0, 1.0);
    drawQuad(0.85 * esz, 0.6 * esz);
    glPopMatrix;
  end;

  //------ draw Super Shields
  //if Boolean(Round(superShields)) then
  if (superShields <> 0) then
  begin
    glPushMatrix;
    sz := hero.getSize(1) * 1.3;
    glColor4f(1.0, 1.0, 1.0, 1.0 - sls * sls);
    glBindTexture(GL_TEXTURE_2D, heroSuperTex);
    glTranslatef(hero.pos[0], hero.pos[1], hero.pos[2]);
    glRotatef(IRAND, 0.0, 0.0, 1.0);
    drawQuad(sz, sz);
    glPopMatrix;
    //------ add a bit of Glitter...
    if (_config.gfxLevel() > 1) and (not game.game_pause) then
    begin
      //float p[3] := { 0.0, 0.0, hero.pos[2] };
      p[0] := 0.0;
      p[1] := 0.0;
      p[2] := hero.pos[2];
      //float v[3] := { 0.01*SRAND, 0.0, 0.0 };
      v[0] := 0.01 * SRAND;
      v[1] := 0.0;
      v[2] := 0.0;
      //float c[4] := { 1.0, 1.0, 0.7, 1.0-sls*sls };
      case uniGlobal.gameFrame mod 2 of
        0:
          begin
            v[1] := -0.3 + FRAND * 0.05;
            p[0] := hero.pos[0];
            p[1] := hero.pos[1] - 0.8;
            _explosions.addGlitter(p, v, c, 0, 0.4 + 0.4 * FRAND);
            v[1] := -0.25 + FRAND * 0.05;
            p[0] := hero.pos[0] + 0.95;
            p[1] := hero.pos[1] + 0.1;
            _explosions.addGlitter(p, v, c, 0, 0.4 + 0.4 * FRAND);
            p[0] := hero.pos[0] - 0.95;
            p[1] := hero.pos[1] + 0.1;
            _explosions.addGlitter(p, v, c, 0, 0.4 + 0.4 * FRAND);
          end;
        1:
          begin
            v[1] := -0.25 + FRAND * 0.05;
            p[0] := hero.pos[0] + 0.95;
            p[1] := hero.pos[1] + 0.1;
            _explosions.addGlitter(p, v, c, 0, 0.4 + 0.4 * FRAND);
            p[0] := hero.pos[0] - 0.95;
            p[1] := hero.pos[1] + 0.1;
            _explosions.addGlitter(p, v, c, 0, 0.4 + 0.4 * FRAND);
          end;
      end;
    end;
  end;

  //---------- Draw ammo flash
  if _config.gfxLevel() > 1 then
  begin
    glPushMatrix;
    glTranslatef(hero.pos[0], hero.pos[1], hero.pos[2]);
    //if Boolean(Round(hero.gunFlash0[0])) then
    if (hero.gunFlash0[0] <> 0) then
    begin
      glBindTexture(GL_TEXTURE_2D, heroAmmoFlash[0]);
      szx := hero.gunFlash0[0];
      szy := 0.46 * szx;
      glColor4f(0.75, 0.75, 0.75, szx);
      glTranslatef(0.275, 0.25, 0.0);
      drawQuad(szy, szy);
      glTranslatef(-0.550, 0.00, 0.0);
      drawQuad(szy, szy);
      glTranslatef(0.275, -0.25, 0.0);
      //if Boolean(Round(hero.gunFlash1[0])) then
      if (hero.gunFlash1[0] <> 0) then
      begin
        glTranslatef(0.45, -0.10, 0.0);
        drawQuad(szy, szy);
        glTranslatef(-0.90, 0.00, 0.0);
        drawQuad(szy, szy);
        glTranslatef(0.45, 0.10, 0.0);
      end;
    end;
    //if Boolean(Round(hero.gunFlash0[1])) then
    if (hero.gunFlash0[1] <> 0) then
    begin
      glBindTexture(GL_TEXTURE_2D, heroAmmoFlash[1]);
      szx := hero.gunFlash0[1];
      szy := 0.8 * szx;
      glColor4f(1.0, 1.0, 1.0, szx);
      glTranslatef(0.0, 0.7, 0.0);
      drawQuad(szy, szy);
      glTranslatef(0.0, -0.7, 0.0);
    end;
    glBindTexture(GL_TEXTURE_2D, heroAmmoFlash[2]);
    //if Boolean(Round(hero.gunFlash0[2])) then
    if (hero.gunFlash0[2] <> 0) then
    begin
      szx := hero.gunFlash0[2];
      szy := 0.65 * szx;
      glColor4f(1.0, 1.0, 1.0, szx);
      glTranslatef(-0.65, -0.375, 0.0);
      drawQuad(szy, szy);
      glTranslatef(0.65, 0.375, 0.0);
    end;
    //if Boolean(Round(hero.gunFlash1[2])) then
    if (hero.gunFlash1[2] <> 0) then
    begin
      szx := hero.gunFlash1[2];
      szy := 0.65 * szx;
      glColor4f(1.0, 1.0, 1.0, szx);
      glTranslatef(0.65, -0.375, 0.0);
      drawQuad(szy, szy);
      glTranslatef(-0.65, 0.375, 0.0);
    end;
    glPopMatrix;
  end;

  //	//-- shield indicator
  glBindTexture(GL_TEXTURE_2D, shldTex);
  glColor4f(0.2, 0.2, 0.2, 0.5);
  glBegin(GL_QUADS);
  szx := 0.6;
  szy := 6.0;
  glTexCoord2f(1.0, 1.0); glVertex3f(statPosShld[0] + szx, statPosShld[1] + szy, statPosShld[2]);
  glTexCoord2f(-2.5, 1.0); glVertex3f(statPosShld[0] - 2.0, statPosShld[1] + szy, statPosShld[2]);
  glTexCoord2f(-2.5, 0.0); glVertex3f(statPosShld[0] - 2.0, statPosShld[1] + 0.0, statPosShld[2]);
  glTexCoord2f(1.0, 0.0); glVertex3f(statPosShld[0] + szx, statPosShld[1] + 0.0, statPosShld[2]);

  glTexCoord2f(3.5, 1.0); glVertex3f(-statPosShld[0] + 2.0, statPosShld[1] + szy, statPosShld[2]);
  glTexCoord2f(0.0, 1.0); glVertex3f(-statPosShld[0] - szx, statPosShld[1] + szy, statPosShld[2]);
  glTexCoord2f(0.0, 0.0); glVertex3f(-statPosShld[0] - szx, statPosShld[1] + 0.0, statPosShld[2]);
  glTexCoord2f(3.5, 0.0); glVertex3f(-statPosShld[0] + 2.0, statPosShld[1] + 0.0, statPosShld[2]);
  glEnd();

  if (_config.gfxLevel > 0) then
  begin
    //-- Shields
    //if ((sl < -0.7) and blink and (shields > 0.0)) or Boolean(Round(superShields)) then
    if ((sl < -0.7) and blink and (shields > 0.0)) or (superShields <> 0) then
      glColor4fv(@statClrWarn)
    else
      glColor4f(0.7 + dc, 0.6 + dc, 0.8 + dc, 0.5 + damageAlpha);
    glPushMatrix;
    glTranslatef(statPosShld[0], statPosShld[1], statPosShld[2]);
    glRotatef(-rot, 0.0, 1.0, 0.0);
    glBegin(GL_QUADS);
    szx := 0.5;
    glTexCoord2f(1.0, sls); glVertex3f(szx, szy, szx);
    glTexCoord2f(0.0, sls); glVertex3f(-szx, szy, szx);
    glTexCoord2f(0.0, 1.0 + sls); glVertex3f(-szx, 0.0, szx);
    glTexCoord2f(1.0, 1.0 + sls); glVertex3f(szx, 0.0, szx);
    glTexCoord2f(0.0, sls); glVertex3f(szx, szy, -szx);
    glTexCoord2f(0.0, 1.0 + sls); glVertex3f(szx, 0.0, -szx);
    glTexCoord2f(1.0, 1.0 + sls); glVertex3f(-szx, 0.0, -szx);
    glTexCoord2f(1.0, sls); glVertex3f(-szx, szy, -szx);
    glTexCoord2f(1.0, sls); glVertex3f(szx, szy, szx);
    glTexCoord2f(1.0, 1.0 + sls); glVertex3f(szx, 0.0, szx);
    glTexCoord2f(0.0, 1.0 + sls); glVertex3f(szx, 0.0, -szx);
    glTexCoord2f(0.0, sls); glVertex3f(szx, szy, -szx);
    glTexCoord2f(1.0, sls); glVertex3f(-szx, szy, -szx);
    glTexCoord2f(1.0, 1.0 + sls); glVertex3f(-szx, 0.0, -szx);
    glTexCoord2f(0.0, 1.0 + sls); glVertex3f(-szx, 0.0, szx);
    glTexCoord2f(0.0, sls); glVertex3f(-szx, szy, szx);

    //if Boolean(Round(shields)) then
    if (shields <> 0) then
    begin
      glTexCoord2f(1.0, 1.0);
      glColor4f(0.3 + sc, 0.4 + sc, 1.0 + sc, 0.5);
      glVertex3f(szx, 0.0, szx);
      glVertex3f(szx, 0.0, -szx);
      glVertex3f(-szx, 0.0, -szx);
      glVertex3f(-szx, 0.0, szx);
    end;
    glEnd;
    glRotatef(rot2, 0.0, 1.0, 0.0);
    glColor4f(0.1 + sc, 0.15 + sc, 0.9 + sc, 0.6 + shieldAlpha);
    glBegin(GL_QUADS);
    szx := 0.4;
    glTexCoord2f(1.0, sl); glVertex3f(szx, szy, szx);
    glTexCoord2f(0.0, sl); glVertex3f(-szx, szy, szx);
    glTexCoord2f(0.0, 1.0 + sl); glVertex3f(-szx, 0.0, szx);
    glTexCoord2f(1.0, 1.0 + sl); glVertex3f(szx, 0.0, szx);

    glTexCoord2f(0.0, sl); glVertex3f(szx, szy, -szx);
    glTexCoord2f(0.0, 1.0 + sl); glVertex3f(szx, 0.0, -szx);
    glTexCoord2f(1.0, 1.0 + sl); glVertex3f(-szx, 0.0, -szx);
    glTexCoord2f(1.0, sl); glVertex3f(-szx, szy, -szx);

    glTexCoord2f(1.0, sl); glVertex3f(szx, szy, szx);
    glTexCoord2f(1.0, 1.0 + sl); glVertex3f(szx, 0.0, szx);
    glTexCoord2f(0.0, 1.0 + sl); glVertex3f(szx, 0.0, -szx);
    glTexCoord2f(0.0, sl); glVertex3f(szx, szy, -szx);

    glTexCoord2f(0.0, sl); glVertex3f(-szx, szy, szx);
    glTexCoord2f(1.0, sl); glVertex3f(-szx, szy, -szx);
    glTexCoord2f(1.0, 1.0 + sl); glVertex3f(-szx, 0.0, -szx);
    glTexCoord2f(0.0, 1.0 + sl); glVertex3f(-szx, 0.0, szx);
    glEnd;
    glPopMatrix;

    //if ((dl < -0.7) and blink) or Boolean(Round(superShields)) then
    if ((dl < -0.7) and blink) or (superShields <> 0) then
    begin
      glColor4fv(@statClrWarn);
      if _config.texBorder then
        glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, @statClrWarn);
    end
    else
    begin
      glColor4f(0.9 + dc, 0.6 + dc, 0.7 + dc, 0.5 + damageAlpha);
      if _config.texBorder then
        glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, @statClrZero);
    end;
    //-- Life
    glPushMatrix;
    glTranslatef(-statPosShld[0], statPosShld[1], statPosShld[2]);
    glRotatef(rot, 0.0, 1.0, 0.0);

    glBegin(GL_QUADS);
    szx := 0.5;
    glTexCoord2f(1.0, dls); glVertex3f(szx, szy, szx);
    glTexCoord2f(0.0, dls); glVertex3f(-szx, szy, szx);
    glTexCoord2f(0.0, 1.0 + dls); glVertex3f(-szx, 0.0, szx);
    glTexCoord2f(1.0, 1.0 + dls); glVertex3f(szx, 0.0, szx);

    glTexCoord2f(0.0, dls); glVertex3f(szx, szy, -szx);
    glTexCoord2f(0.0, 1.0 + dls); glVertex3f(szx, 0.0, -szx);
    glTexCoord2f(1.0, 1.0 + dls); glVertex3f(-szx, 0.0, -szx);
    glTexCoord2f(1.0, dls); glVertex3f(-szx, szy, -szx);

    glTexCoord2f(1.0, dls); glVertex3f(szx, szy, szx);
    glTexCoord2f(1.0, 1.0 + dls); glVertex3f(szx, 0.0, szx);
    glTexCoord2f(0.0, 1.0 + dls); glVertex3f(szx, 0.0, -szx);
    glTexCoord2f(0.0, dls); glVertex3f(szx, szy, -szx);

    glTexCoord2f(0.0, dls); glVertex3f(-szx, szy, szx);
    glTexCoord2f(1.0, dls); glVertex3f(-szx, szy, -szx);
    glTexCoord2f(1.0, 1.0 + dls); glVertex3f(-szx, 0.0, -szx);
    glTexCoord2f(0.0, 1.0 + dls); glVertex3f(-szx, 0.0, szx);
    //if Boolean(Round(damage)) then
    if (damage <> 0) then
    begin
      glTexCoord2f(1.0, 1.0);
      glColor4f(1.0 + dc, 0.0 + dc, 0.0 + dc, 0.5);
      glVertex3f(szx, 0.0, szx);
      glVertex3f(szx, 0.0, -szx);
      glVertex3f(-szx, 0.0, -szx);
      glVertex3f(-szx, 0.0, szx);
    end;
    glEnd;

    glRotatef(-rot2, 0.0, 1.0, 0.0);
    glColor4f(1.0 + dc, 0.0 + dc, 0.0 + dc, 0.6 + damageAlpha);
    glBegin(GL_QUADS);
    szx := 0.4;
    glTexCoord2f(1.0, dl); glVertex3f(szx, szy, szx);
    glTexCoord2f(0.0, dl); glVertex3f(-szx, szy, szx);
    glTexCoord2f(0.0, 1.0 + dl); glVertex3f(-szx, 0.0, szx);
    glTexCoord2f(1.0, 1.0 + dl); glVertex3f(szx, 0.0, szx);

    glTexCoord2f(0.0, dl); glVertex3f(szx, szy, -szx);
    glTexCoord2f(0.0, 1.0 + dl); glVertex3f(szx, 0.0, -szx);
    glTexCoord2f(1.0, 1.0 + dl); glVertex3f(-szx, 0.0, -szx);
    glTexCoord2f(1.0, dl); glVertex3f(-szx, szy, -szx);

    glTexCoord2f(1.0, dl); glVertex3f(szx, szy, szx);
    glTexCoord2f(1.0, 1.0 + dl); glVertex3f(szx, 0.0, szx);
    glTexCoord2f(0.0, 1.0 + dl); glVertex3f(szx, 0.0, -szx);
    glTexCoord2f(0.0, dl); glVertex3f(szx, szy, -szx);

    glTexCoord2f(0.0, dl); glVertex3f(-szx, szy, szx);
    glTexCoord2f(1.0, dl); glVertex3f(-szx, szy, -szx);
    glTexCoord2f(1.0, 1.0 + dl); glVertex3f(-szx, 0.0, -szx);
    glTexCoord2f(0.0, 1.0 + dl); glVertex3f(-szx, 0.0, szx);
    glEnd;
    glPopMatrix;
  end
  else
  begin
    szx := 0.8;
    //if ((sl < -0.7) and blink and (shields > 0.0)) or Boolean(Round(superShields)) then
    if ((sl < -0.7) and blink and (shields > 0.0)) or (superShields <> 0) then
      glColor4fv(@statClrWarn)
    else
      glColor4f(0.0 + sc, 0.35 + sc, 1.0 + sc, 0.7 + shieldAlpha);
    //-- Shields
    glBegin(GL_QUADS);
    glTexCoord2f(1.0, sl); glVertex3f(statPosShld[0], statPosShld[1] + szy, statPosShld[2]);
    glTexCoord2f(0.0, sl); glVertex3f(statPosShld[0] - szx, statPosShld[1] + szy, statPosShld[2]);
    glTexCoord2f(0.0, 1.0 + sl); glVertex3f(statPosShld[0] - szx, statPosShld[1], statPosShld[2]);
    glTexCoord2f(1.0, 1.0 + sl); glVertex3f(statPosShld[0], statPosShld[1], statPosShld[2]);
    //-- Life
    if (dl < -0.7) and blink then
      glColor4fv(@statClrWarn)
    else
      glColor4f(1.0 + dc, 0.0 + dc, 0.0 + dc, 0.7 + damageAlpha);
    glTexCoord2f(1.0, dl); glVertex3f(-statPosShld[0], statPosShld[1] + szy, statPosShld[2]);
    glTexCoord2f(1.0, 1.0 + dl); glVertex3f(-statPosShld[0], statPosShld[1], statPosShld[2]);
    glTexCoord2f(0.0, 1.0 + dl); glVertex3f(-statPosShld[0] + szx, statPosShld[1], statPosShld[2]);
    glTexCoord2f(0.0, dl); glVertex3f(-statPosShld[0] + szx, statPosShld[1] + szy, statPosShld[2]);
    glEnd;
  end;


  //-- print message if we're paused...
  if game.game_pause then
  begin
    off[0] := 2.0 * sin(uniGlobal.frame * 0.01);
    off[1] := 1.0 * cos(uniGlobal.frame * 0.011);
    glPushMatrix;
    glTranslatef(-14.5, -3.0, 0.0);
    glScalef(0.21, 0.21, 1.0);
    glPushMatrix;
    glColor4f(1.0, 1.0, 1.0, 0.10 * Abs(sin(uniGlobal.frame * 0.05)));
    //game.ftFont.Render("p a u s e d");
    ftglRenderFont(uniGlobal.ftFont, 'p a u s e d');
    glPopMatrix;
    glColor4f(1.0, 1.0, 1.0, 0.10 * Abs(sin(uniGlobal.frame * 0.03)));
    glTranslatef(off[0], off[1], 0.0);
    //game.ftFont.Render("p a u s e d");
    ftglRenderFont(uniGlobal.ftFont, 'p a u s e d');
    glPopMatrix;
  end;
  if (uniGlobal.tipShipPast = 1) and (uniGlobal.gameLevel = 1) then
  begin
    Inc(uniGlobal.tipShipPast);
    tipShipShow := 200;
  end;
  if (uniGlobal.tipSuperShield = 1) and (uniGlobal.gameLevel = 1) then
  begin
    Inc(uniGlobal.tipSuperShield);
    tipSuperShow := 200;
  end;
  if tipShipShow > 0 then
  begin
    Dec(tipShipShow);
    glPushMatrix;
    glTranslatef(-16, 13.0, 0.0);
    glScalef(0.035, 0.035, 1.0);
    glColor4f(1.0, 1.0, 1.0, tipShipShow / 300.0);
    //const char *str := "do not let -any- ships past you! each one costs you a life!";
    //game.ftFont.Render(str);
    ftglRenderFont(uniGlobal.ftFont, PAnsiChar(Str1));
    glPopMatrix;
  end;
  if tipSuperShow > 0 then
  begin
    Dec(tipSuperShow);
    glPushMatrix;
    glTranslatef(-16, 13.0, 0.0);
    glScalef(0.035, 0.035, 1.0);
    glColor4f(1.0, 1.0, 1.0, tipSuperShow / 300.0);
    //const char *str := "let super shields pass by for an extra life!";
    //game.ftFont.Render(str);
    ftglRenderFont(uniGlobal.ftFont, PAnsiChar(Str2));
    glPopMatrix;
  end;
end;

procedure StatusDisplay.drawQuad(szx, szy: Single);
begin
  glBegin(GL_TRIANGLE_STRIP);
  glTexCoord2f(1.0, 0.0); glVertex3f(szx, szy, 0.0);
  glTexCoord2f(0.0, 0.0); glVertex3f(-szx, szy, 0.0);
  glTexCoord2f(1.0, 1.0); glVertex3f(szx, -szy, 0.0);
  glTexCoord2f(0.0, 1.0); glVertex3f(-szx, -szy, 0.0);
  glEnd;
end;

procedure StatusDisplay.enemyWarning(v: Single);
begin
  if v > enemyWarn then enemyWarn := v;
end;

procedure StatusDisplay.loadTextures;
var
  i: Integer;
  fileName: string;
begin
  LoadTexture('png/statBar.png', statTex);
  LoadTexture('png/shields.png', shldTex);
  LoadTexture('png/stat-top.png', topTex);
  LoadTexture('png/heroSuper.png', heroSuperTex);
  LoadTexture('png/heroShields.png', heroShieldTex);

  for i := 0 to NUM_HERO_AMMO_TYPES - 1 do
  begin
    fileName := 'png/heroAmmoFlash' + FormatCurr('0#', i) + '.png';
    LoadTexture(filename, heroAmmoFlash[i]);
  end;
  LoadTexture('png/useFocus.png', useFocus);

  for i := 0 to NUM_HERO_ITEMS - 1 do
  begin
    fileName := 'png/useItem' + FormatCurr('0#', i) + '.png';
    LoadTexture(filename, useItem[i]);
  end;
end;

procedure StatusDisplay.setAmmoAlpha(_in: Single);
begin
  ammoAlpha := _in;
end;

procedure StatusDisplay.setDamageAlpha(_in: Single);
begin
  damageAlpha := _in;
end;

procedure StatusDisplay.setShieldAlpha(_in: Single);
begin
  shieldAlpha := _in;
end;

end.

